package tt.dz.mvc.controller.sys;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Properties;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tt.dz.entity.base.JsonCommon;
import tt.dz.util.OmsConstant.MsgCodeEnum;

@Controller
public class CopyrightController {
	private Logger log = LoggerFactory.getLogger(CopyrightController.class);
	
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/getCopyright")
	@ResponseBody
	public JsonCommon getCopyright(HttpServletRequest request,HttpServletResponse response) {
		//CopyrightUtil  copyrightUtil =new CopyrightUtil();
		
		//return copyrightUtil.getCopyright();
		String filePath = "WEB-INF\\classes\\copyRight.properties";   
		//获取servlet的上下文    
		ServletContext context = request.getServletContext();   
		String webRootPath = context.getRealPath("\\");   
		//最后得到文件的绝对路径    
		String path = webRootPath+filePath ;    
	
		String classPath = this.getClass().getClassLoader().getResource("/").getPath();
	    String rootPath  = "";
	    //windows下
	    if("\\".equals(File.separator)){   
	        rootPath  = classPath.substring(1,classPath.indexOf("/WEB-INF/classes"));
	        rootPath = rootPath.replace("/", "\\");
	        path = rootPath+"\\WEB-INF\\classes\\copyRight.properties"  ;
	    }
	    //linux下
	    if("/".equals(File.separator)){   
	        rootPath  = classPath.substring(0,classPath.indexOf("/WEB-INF/classes"));
	        rootPath = rootPath.replace("\\", "/");
	        path = rootPath+"/WEB-INF/classes/copyRight.properties" ;;
	    }
		
	    log.info(path);
	    
        String copyRight="";
        Properties prop =  new  Properties();  
        try  {
        //Reader in = new InputStreamReader(new FileInputStream("D:\\workspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\dz_OMS_V2.1\\WEB-INF\\classes\\copyRight.properties"), "UTF-8");
        	Reader in = new InputStreamReader(new FileInputStream(path), "UTF-8");
            prop.load(in);  
            copyRight = prop.getProperty( "dz.copyRight.txt" ).trim();  
        }  catch  (IOException e) {  
            e.printStackTrace();  
        } 
        JsonCommon<String> json = new JsonCommon<String>(MsgCodeEnum.SUCCESS.getMsgCode(),MsgCodeEnum.SUCCESS.getMsgInfo());
		json.setPojo(copyRight);
		return json;
	}

}
